package com.ruoyi.aqsc.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;

import com.ruoyi.aqsc.domain.Label;
import com.ruoyi.aqsc.service.LabelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 培训教育/标签管理
 */
@RestController//异步请求
@RequestMapping("label")
public class LabelController extends BaseController {
      //注入业务层
     @Autowired
    private LabelService service;

    /**
     * 查询列表
     * @param label
     * @return
     */
    @GetMapping("/list")
    @RequiresPermissions("label:list")
    public TableDataInfo list(Label label){
        startPage();
        List<Label> labels = service.queryLabels(label);
        return getDataTable(labels);
    }

    /**
     * 新增或编辑
     * @param label
     * @return
     */
    @PostMapping("/save")
    @Log(title = "区域管理",businessType = BusinessType.INSERT)
    public AjaxResult save(@RequestBody Label label){
        boolean b = service.saveOrUpdata(label);
        return AjaxResult.success(b);
    }

    /**
     * 通过id删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @Log(title="区域管理",businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable Integer id){
        boolean b = service.removeById(id);
        return AjaxResult.success(b);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @DeleteMapping("/deletes/{ids}")
    @Log(title="区域管理",businessType = BusinessType.DELETE)
    public AjaxResult deletes(@PathVariable Integer[] ids){
        boolean b = service.removeByIds(ids);
        return AjaxResult.success(b);
    }

    /**
     * 通过id查一个
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable Integer id){
        Label label = service.queryById(id);
        return AjaxResult.success(label);
    }

}
